package com.example.demo.service;

import com.example.demo.entity.BookType;
import com.example.demo.repository.BookTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class BookTypeService {

    @Autowired
    private BookTypeRepository bookTypeRepository;

    public List<BookType> findAll() {
        return bookTypeRepository.findAll();
    }

    public Optional<BookType> findById(Integer id) {
        return bookTypeRepository.findById(id);
    }

    public Optional<BookType> findByName(String name) {
        return bookTypeRepository.findByName(name);
    }

    public BookType save(BookType bookType) {
        return bookTypeRepository.save(bookType);
    }

    public void deleteById(Integer id) {
        bookTypeRepository.deleteById(id);
    }

    // 添加模糊搜索方法
    public List<BookType> searchByName(String name) {
        return bookTypeRepository.findByNameContaining(name);
    }
}